package com.wangxinrou.wangxinrou_surprisemeal.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wangxinrou.wangxinrou_surprisemeal.mapper.RecommendationMapper;
import com.wangxinrou.wangxinrou_surprisemeal.model.Recommendation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RecommendationService {
    @Autowired
    private RecommendationMapper recommendationMapper;

    // 创建新的推荐
    public void createRecommendation(Recommendation recommendation) {
        // 可以在这里添加验证逻辑
        recommendationMapper.insert(recommendation);
    }

    // 根据推荐ID获取推荐
    public Recommendation getRecommendationById(int recId) {
        return recommendationMapper.selectById(recId);
    }

    // 获取所有推荐
    public List<Recommendation> getAllRecommendations() {
        return recommendationMapper.selectList(null);
    }

    // 根据用户ID获取推荐
    public List<Recommendation> getRecommendationsByUserId(int userId) {
        QueryWrapper<Recommendation> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        return recommendationMapper.selectList(queryWrapper);
    }

    // 更新推荐评分
    public void updateRecommendationRating(Recommendation recommendation) {
        recommendationMapper.updateById(recommendation);
    }

    // 根据推荐ID删除推荐
    public void deleteRecommendation(int recId) {
        recommendationMapper.deleteById(recId);
    }
}
